package com.example.spring.config;

import com.example.spring.bean.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @功能
 * @作者 沈飞超
 * @日期 2020年08月27日 20:01
 */
@Configuration //告诉spring这是个配置类
//@ComponentScan(value = "com.example.spring", excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, Service.class})
//})
//@ComponentScan(value = "com.example.spring", useDefaultFilters = false,
//        includeFilters = {
//                @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class})
//        })
//@ComponentScans(value = {
//        @ComponentScan(value = "com.example.spring", includeFilters = {
//                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})
//        }, useDefaultFilters = false)
//})
// @ComponentScan 扫描执行路径的包
//excludeFilters 默认排除注解标注的类 Filter参数是注解的class
//excludeFilters 默认指定注解标注的类 Filter参数是注解的class
//FilterType.ANNOTATION 按照注解
//@Import({MyImportSelector.class})
//@Import({MyImportBeanDefinitionRegistrar.class})
public class MyConfig {

//    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) //默认单例
//    @Lazy //多实例是懒加载 默认是单实例的恶汉加载
    @Bean("person") //返回值就是要注册的类  方法名为bean的ID
    public Person person() {
        System.out.println("加载person");
        return new Person("沈飞超", 18);
    }

    @Conditional({
            WindowsCondition.class
    })
    @Bean("bill")
    public Person person2() {
        return new Person("bill", 18);
    }

    @Conditional({
            LinuxCondition.class
    })
    @Bean("linus")
    public Person person3() {
        return new Person("linus", 18);
    }


    @Bean()
    public MyFactoryBean myFactoryBean() {
        return new MyFactoryBean();
    }
}
